﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using MixScript.BLL.FI;

namespace MixScriptWeb.Accounting.ReportFinnance
{
    public partial class IncomingStatment_Rpt : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();
            cIncomeStatetment istatment = new cIncomeStatetment();
            dt = istatment.ListOfData();
            rptLaporan.DataSource = dt;
            rptLaporan.DataBind();
            lblPeriod.Text = (String)Session["Period"];
            lblCurrency.Text = (String)Session["Cur"];

        }
        protected void rptLaporan_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            Repeater subrepeter = new Repeater();
            if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
            {
                Label idLbl = new Label();
                idLbl = (Label)e.Item.FindControl("lblID");
                subrepeter = (Repeater)e.Item.FindControl("rptSubLaporan");
                cIncomeStatetment istatment = new cIncomeStatetment();
                subrepeter.DataSource = istatment.SubListOfData(idLbl.Text);
                subrepeter.DataBind();


                Label lblName = new Label();
                lblName = (Label)e.Item.FindControl("lblName");
                Label lblProfit = new Label();
                LiteralControl lt = new LiteralControl();
                //lt.Text = "<div style='font-weight: bold'>";
                //LiteralControl lt2 = new LiteralControl();
                //lt2.Text = "</div>";
                //e.Item.Controls.Add(lt);
                //lblProfit.Text = "PROFIT / LOST AFTER " + lblName.Text;
                //e.Item.Controls.Add(lblProfit);
                //e.Item.Controls.Add(lt2);
            }
            if (e.Item.ItemType == ListItemType.Footer)
            {
                Label lblName = new Label();
                Label lblCurrent = new Label();
                Label lblAccumulated = new Label();
                lblName = (Label)e.Item.FindControl("lblProfit");
                lblCurrent = (Label)e.Item.FindControl("lblProfitCurrent");
                lblAccumulated = (Label)e.Item.FindControl("lblProfitAccumulated");
                lblName.Text = "PROFIT / LOST :";
                lblCurrent.Text = String.Format("{0:##,##.00}", (Decimal)Session["current"]);
                lblAccumulated.Text = String.Format("{0:##,##.00}", (Decimal)Session["accum"]);

            }


        }
        protected void rptSubLaporan_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
            {
                Label idLbl = new Label();
                Label idCurrent = new Label();
                Label idAccumulated = new Label();
                idLbl = (Label)e.Item.FindControl("lblSubNameID");
                idCurrent = (Label)e.Item.FindControl("idCurrent");
                idAccumulated = (Label)e.Item.FindControl("idAccumulated");
                cIncomeStatetment istatment = new cIncomeStatetment();
                Decimal curr, accum;

                curr = istatment.getCurrent(idLbl.Text);
                accum = istatment.getAccumulated(idLbl.Text);
                idCurrent.Text = curr.ToString();
                idAccumulated.Text = accum.ToString();
                if (Session["current"] != null)
                    Session["current"] = (Decimal)Session["current"] + curr;
                else
                    Session["current"] = curr;
                if (Session["accum"] != null)
                    Session["accum"] = (Decimal)Session["accum"] + accum;
                else
                    Session["accum"] = accum;
            }
            if (e.Item.ItemType == ListItemType.Footer)
            {
                Label lblName = new Label();
                Label lblCurrent = new Label();
                Label lblAccumulated = new Label();
                lblName = (Label)e.Item.FindControl("lbltotName");
                lblCurrent = (Label)e.Item.FindControl("lblTotalCurrent");
                lblAccumulated = (Label)e.Item.FindControl("lblTotalAccumulated");
                lblName.Text = "## TOTAL :";
                lblCurrent.Text = String.Format("{0:##,##.00}", (Decimal)Session["current"]);
                lblAccumulated.Text = String.Format("{0:##,##.00}", (Decimal)Session["accum"]);

            }


        }
    }
}